import pinia from '@/store'
import useSettingsStore from '@/store/modules/settings'

// 固定路由（默认路由），
let constantRoutes = [
  {
    path: '/',
    redirect: '/dashboard',
    meta: {
      title: ''
    }
  },
  {
    path: '/login',
    name: 'login',
    component: () => import('@/views/login/login.vue'),
    meta: {
      whiteList: true,
      title: '登录'
    }
  },
  {
    path: '/401',
    name: 'notAuth',
    component: () => import('@/views/401.vue'),
    meta: {
      title: '无权限',
      whiteList: true
    }
  },
  {
    path: '/:error*',
    name: 'notFound',
    component: () => import('@/views/[...all].vue'),
    meta: {
      title: '找不到页面',
      sidebar: false,
      breadcrumb: false
    }
  }
]

// 系统路由
let systemRoutes = [
  {
    path: '/dashboard',
    component: () => import('@/layout/index.vue'),
    meta: {
      title: () => {
        return useSettingsStore().dashboard.title
      },
      breadcrumb: false
    },
    children: [
      {
        path: '',
        name: 'dashboard',
        component: () => import('@/views/index.vue'),
        meta: {
          title: () => {
            return useSettingsStore().dashboard.title
          },
          i18n: 'route.dashboard',
          breadcrumb: false
        }
      }
    ]
  },
  {
    path: '/reload',
    component: () => import('@/layout/index.vue'),
    meta: {
      title: '重新加载',
      breadcrumb: false
    },
    children: [
      {
        path: '',
        name: 'reload',
        component: () => import('@/views/reload.vue'),
        meta: {
          title: '重新加载',
          breadcrumb: false
        }
      }
    ]
  }
]

import Home from './modules/home'
// import Class from './modules/class'
import Sign from './modules/sign' // 签订管理
import Template from './modules/template' // 模板管理
import Business from './modules/business' // 业务管理
import Contract from './modules/contract' // 合同管理
import WhiteList from './modules/whiteList' // 白名单
import System from './modules/system' // 系统账号管理

// 动态路由（异步路由、导航栏路由）
let asyncRoutes = [
  {
    meta: {
      title: '电子合同系统',
      i18n: 'route.demo',
      icon: 'sidebar-default'
    },
    children: [
      Home,
      // Class,
      Sign,
      Template,
      Business,
      Contract,
      WhiteList,
      System
    ]
  }
]

import { setupLayouts } from 'virtual:generated-layouts'
import generatedRoutes from 'virtual:generated-pages'

if (useSettingsStore(pinia).app.routeBaseOn === 'filesystem') {
  constantRoutes = generatedRoutes.filter(item => {
    return item.meta?.enabled !== false && item.meta?.constant === true
  })
  asyncRoutes = setupLayouts(generatedRoutes.filter(item => {
    return item.meta?.enabled !== false && item.meta?.constant !== true && item.meta?.layout !== false
  }))
}

export {
  constantRoutes,
  systemRoutes,
  asyncRoutes
}
